﻿// PCAndBasic.cpp: 实现文件
//

#include "pch.h"
#include "afxdialogex.h"
#include "PCAndBasic.h"
#include "Data.h"
#include <afx.h>
#include "liwishell.h"
#include "LiWi.h"


// PCAndBasic 对话框

IMPLEMENT_DYNAMIC(PCAndBasic, CDialogEx)

PCAndBasic::PCAndBasic(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PCAndBasic, pParent)
{

}

PCAndBasic::~PCAndBasic()
{
}

void PCAndBasic::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(PCAndBasic, CDialogEx)
	ON_BN_CLICKED(IDC_Do1, &PCAndBasic::OnBnClickedDo1)
	ON_BN_CLICKED(IDC_Do2, &PCAndBasic::OnBnClickedDo2)
	ON_BN_CLICKED(IDC_BtnRead, &PCAndBasic::OnBnClickedBtnread)
END_MESSAGE_MAP()


// PCAndBasic 消息处理程序


BOOL PCAndBasic::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	GetDlgItem(IDC_Write1A0)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read1A0)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Write2A0)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read2A0)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Write1A1)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read1A1)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Write2A1)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read2A1)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Write1A2)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read1A2)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Write2A2)->SetWindowTextW(_T("0"));
	GetDlgItem(IDC_Read2A2)->SetWindowTextW(_T("0"));
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

/// <summary>
/// 动作1
/// </summary>
void PCAndBasic::OnBnClickedDo1()
{
	// TODO: 在此添加控件通知处理程序代码
	GetDlgItem(IDC_NowToDo)->SetWindowTextW(_T("1"));
	CString str[3];
	GetDlgItem(IDC_Write1A0)->GetWindowTextW(str[0]);
	GetDlgItem(IDC_Write1A1)->GetWindowTextW(str[1]);
	GetDlgItem(IDC_Write1A2)->GetWindowTextW(str[2]);
	for (int i = 0; i < 3; i++)
	{
		array[i] = _ttof(str[i]);
	}
	PMC_SetUserArray(Data::handle, "array_para", 0, 3, array);	//设置全局数组
	Sleep(200);
	cmd = 1;
	PMC_SetUserVar(Data::handle, "cmd_data", cmd);				//设置全局变量
}


void PCAndBasic::OnBnClickedDo2()
{
	// TODO: 在此添加控件通知处理程序代码
	GetDlgItem(IDC_NowToDo)->SetWindowTextW(_T("2"));
	CString str[3];
	GetDlgItem(IDC_Write2A0)->GetWindowTextW(str[0]);
	GetDlgItem(IDC_Write2A1)->GetWindowTextW(str[1]);
	GetDlgItem(IDC_Write2A2)->GetWindowTextW(str[2]);
	for (int i = 0; i < 3; i++)
	{
		array[i] = _ttof(str[i]);
	}
	PMC_SetUserArray(Data::handle, "array_para", 5, 3, array);		//设置全局数组
	Sleep(200);
	cmd = 2;
	PMC_SetUserVar(Data::handle, "cmd_data", cmd);					//设置全局变量
}


void PCAndBasic::OnBnClickedBtnread()
{
	// TODO: 在此添加控件通知处理程序代码
	float m_ArrayShow[10];
	CString str[10];
	cmd = 3;
	GetDlgItem(IDC_NowToDo)->SetWindowTextW(_T("3"));
	PMC_GetUserVar(Data::handle, "cmd_data", &cmd);	//读取全局变量
	Sleep(10);
	PMC_GetUserArray(Data::handle, "array_para", 0, 9, m_ArrayShow);	//读取全局数组,注意BASIC定义的数组最好比PC端实际数据大1，BASIC数组最后一个元素访问时会越界
	for (int i = 0; i < 10; i++)
	{
		str[i].Format(_T("%.2f"), m_ArrayShow[i]);
	}
	GetDlgItem(IDC_Read1A0)->SetWindowTextW(str[0]);
	GetDlgItem(IDC_Read1A1)->SetWindowTextW(str[1]);
	GetDlgItem(IDC_Read1A2)->SetWindowTextW(str[2]);
	GetDlgItem(IDC_Read2A0)->SetWindowTextW(str[5]);
	GetDlgItem(IDC_Read2A1)->SetWindowTextW(str[6]);
	GetDlgItem(IDC_Read2A2)->SetWindowTextW(str[7]);

}
